/**
 * Created by jijin on 2017/7/10.
 *
 * api service
 */
import showToast from '../utils/toast';
//api
const baseApi = 'https://api.surmon.me';
const fetchService = (url, option={}) => {
  return fetch(url, option)
    .then(res => res.json())
    .then(json => {
      showToast(json.message);
      return json;
    })
    .catch(err => {
      alert('网络错误');
      console.warn(err);
    });
};

export default class Api {
  //获取文章列表
  static getArticleList(page) {
    let queryParams = page ? `?page=${page}` : '';
    return fetchService(`${baseApi}/article${queryParams}`);
  }
}